package com.gthncz;

import java.util.Scanner;

public class YuanDemo1 {

    public static void main(String[] agrs) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int N = sc.nextInt();
            if (N < 0) {
                System.out.print("");
                continue;
            }

            int[] tree = new int[N+1];
            for (int j=1; j<=N; ++j) {
                tree[j] = sc.nextInt();
            }

            boolean isFisrt = true;

            // 按逆时针打印完全二叉树
            int treeHeight = (int)Math.log(N) + 1;
            for (int i=1; i<=N; ++i) {
                if (tree[i] > 0) {
                    // 以 tree[i] 为 root 开始遍历
                    int rootHeight = (int) Math.log(i) +1;
                    int leafHeight = treeHeight - rootHeight + 1;

                    // 遍历左边界
                    int p = i;
                    do {
                        if (isFisrt) {
                            isFisrt = false;
                            System.out.printf("%d", tree[p]);
                        } else {
                            System.out.printf(" %d", tree[p]);
                        }
                        tree[p] *= -1;
                    } while (((int)Math.log(p = p*2)+1 <= leafHeight));

                    // 回退到 leaf 层
                    p = p >> 1;

                    // 打印底层
                    if (leafHeight > rootHeight) {
                        while ((p = p+1) < Math.min(N+1, Math.pow(2, leafHeight))) {
                            System.out.printf(" %d", tree[p]);
                            tree[p] *= -1;
                        }
                    }

                    // 依次向上打印
                    p = p-1;
                    int tmpHeight = leafHeight;
                    if (leafHeight > rootHeight) {
                        while ((tmpHeight = (int)Math.log((p=p>>1))+1) > rootHeight) {
                            if (p == Math.pow(2, tmpHeight)-1) {
                                System.out.printf(" %d", tree[p]);
                                tree[p] *= -1;
                            } else {
                                p = p +1;
                                while ((p=p+1) < Math.pow(2, tmpHeight)-1) {
                                    System.out.printf(" %d", tree[p]);
                                    tree[p] *= -1;
                                }
                            }
                        }
                    }

                } // else continue;
            }


        }



    }


}
